package com.mszlu.blog.controller;


import com.mszlu.blog.common.aop.LoginAnnotation;
import com.mszlu.blog.service.ArticleService;
import com.mszlu.blog.vo.Result;
import com.mszlu.blog.vo.params.ArticleParam;
import com.mszlu.blog.vo.params.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@RestController
@RequestMapping("articles")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    /**
     * 首页文章列表返回
     * @param pageParams
     * @return
     */
    @PostMapping
    @LoginAnnotation(model = "文章",opertaor = "获取文章列表")
    public Result listArticle(@RequestBody PageParams pageParams){
        return articleService.listArticle(pageParams);
    }

    @PostMapping("hot")
    @ResponseBody
    public Result findHostArticle(){
      return   articleService.findArticlehot();
    }
    @RequestMapping(value = "new",method = RequestMethod.POST)
    public Result findByNewDate(){
        return  articleService.findArticleNewDate();
    }

    @RequestMapping(value = "listArchives",method = RequestMethod.POST)
    public Result findByYear(){
        return  articleService.findByYear();
    }

    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") Long id){
        return articleService.findArticleById(id);

    }


    @PostMapping("publish")
    public Result publish(@RequestBody ArticleParam articleParam){
        return articleService.publish(articleParam);
    }



    /*@PostMapping("view/{id}")
    public Result findArticleDetailById(@PathVariable("id") Long id){
        return articleService.findArticleDetailById(id);
    }*/
}
